package com.mine;

import org.junit.Test;

public class IpToInteger {
    @Test
    public int convert(String ip) {
        String[] split = ip.split(".");
        if (split.length != 4) {
            throw new RuntimeException("不是ip数据");
        }
        int res = 0;
        for (int i = 0; i < split.length; i++) {
            int tmp = Integer.parseInt(split[i]);
            res = res << 8 * i;
            res += tmp;
        }
        return res;
    }

}
